package net.thxjj.mobileServer.util.sampleUtil;

import com.amazonaws.services.iot.client.AWSIotException;
import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotMqttClient;
import com.amazonaws.services.iot.client.AWSIotQos;
import net.thxjj.mobileServer.entity.DataBean;

public  class NonBlockingPublisher implements Runnable{

    private static final String TestTopic = "st/siterlink/to_gw/";

    private final AWSIotMqttClient awsIotClient;
    private DataBean dataBean;

    public NonBlockingPublisher(AWSIotMqttClient awsIotClient, DataBean dataBean) {
        this.awsIotClient = awsIotClient;
        this.dataBean = dataBean;
    }


    @Override
    public void run() {

            AWSIotMessage message = new NonBlockingPublishListener(TestTopic+dataBean.getHw_id()+"_123456", AWSIotQos.QOS1, this.dataBean.toString());
            try {
                awsIotClient.publish(message);
            } catch (AWSIotException e) {
                System.out.println(System.currentTimeMillis() + ": publish failed for "+this.dataBean.toString());
            }
    }
}
